<?php
class pay_failure_log_model extends CI_Model
{
    private $table = 'pay_failure_log';
    
    public function total($search_param=array())
    {
        if (!empty($search_param['order_sn'])) {
            $this->db->where('order_sn', $search_param['order_sn']);
        }
        if (!empty($search_param['startDate'])){
            $this->db->where('created_at >=', date('Y-m-d H:i:s',strtotime($search_param['startDate'])));
        }
        if (!empty($search_param['endDate'])) {
            $this->db->where('created_at <=', date('Y-m-d H:i:s',strtotime($search_param['endDate'])));
        }
        return $this->db->count_all_results($this->table);
    }
    
    public function page_list($pageNum, $num, $search_param=array())
    {
        if (!empty($search_param['order_sn'])) {
            $this->db->where('order_sn', $search_param['order_sn']);
        }
        if (!empty($search_param['startDate'])){
            $this->db->where('created_at >=', date('Y-m-d H:i:s',strtotime($search_param['startDate'])));
        }
        if (!empty($search_param['endDate'])) {
            $this->db->where('created_at <=', date('Y-m-d H:i:s',strtotime($search_param['endDate'])));
        }
        $this->db->order_by('created_at','desc');
        $this->db->limit(20, $num);
        return $this->db->get($this->table);
    }

    public function findById($id)
    {
        $this->db->where('id', $id);
        return $this->db->get($this->table);
    }
}